#include<stdio.h>
#include<stdlib.h>
#include<string.h>
// 一个人赶着鸭子去每个村庄卖，每经过一个村子卖去所赶鸭子的一半又一只。这样他经过了七个村子后还剩两只鸭子，
// 问他出发时共赶多少只鸭子？经过每个村子卖出多少只鸭子？


// n 只鸭子
// f(7) =(n -  (n/2 + 1) = 2 ; n/2 = 3 n = 6

// f(k) = n - (n/2*k + k)

// 2 + (n/(2*k) + k)

int getInitNumber(int n, int k){

    int sum = (n + 1)*2;
    if(k > 1){
        sum = getInitNumber(sum,k-1); 
    }
    return sum;
}
// 没有递归
int getInitNumberTwoMethod(int number,int count){

    for(int index = 1;index <= count;++index){

        int tmp = (number+1)*2;
        number = tmp;
    }
    return number;
}

int
main(int argc,char * argv[]){

    int sum = getInitNumber(2,10);
    int sumTwo = getInitNumberTwoMethod(2,10);

    printf("sum = %d,sumTwo = %d.\n",sum,sumTwo);
    // check
    // for(int i = 1;i <= 7;++i){
    //     sum = sum - sum/2 - 1;
    // }
    if(sum == sumTwo){
        printf("is right.\n");
    }
    // printf("left = %d.\n",sum);
    return EXIT_SUCCESS;
}
